<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>WindowEvent</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<font face="Verdana, sans-serif" size="2"><p align="center"><b><font size="4">WindowEvent()</font></b></p>
<p><b>语法</b></p><blockquote>

Event = <font color="#3A3966"><b>WindowEvent</b></font>()    </blockquote>

</blockquote>
<b>概要</b><br><blockquote>



Checks if an event has occurred on any of the opened windows. 

 

</blockquote><p><b>参数</b></p><blockquote>
无.


</blockquote><p><b>返回值</b></p><blockquote>



The next event from the event queue and or zero if there are no more events. 
Unlike <a href="waitwindowevent.html">WaitWindowEvent()</a> it doesn't wait for the next event - it always returns immediately. 
<br>
<br>
This makes it useful for window event loops, where other processing needs to be done without waiting 
for an event to happen (e.g. <a href="../network/index.html">Network</a> transactions) and therefore 
<a href="waitwindowevent.html">WaitWindowEvent()</a> can't be used. 
<br>
<br>
It must be handled with care though if used on a continuing basis, because unlike 
<a href="waitwindowevent.html">WaitWindowEvent()</a>, it will not give CPU time to other programs while waiting 
for an event and therefore consume all CPU power. In this case, either <a href="../system/delay.html">Delay()</a> should 
be used somewhere in the loop or <a href="waitwindowevent.html">WaitWindowEvent()</a> with a small timeout value. 
<br>
<br>
To get the window number in which the event occurred, use the <a href="eventwindow.html">EventWindow()</a> function. 
<br>
<br>
Possible Events are : 
 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_Event_Menu</font>            : a <a href="../menu/index.html">menu</a> has been selected
  <font color="#924B72">#PB_Event_Gadget</font>          : a <a href="../gadget/index.html">gadget</a> has been pushed
  <font color="#924B72">#PB_Event_SysTray</font>         : an icon in the <a href="../systray/index.html">systray</a> zone was clicked
  <font color="#924B72">#PB_Event_Timer</font>           : a <a href="addwindowtimer.html">timer</a> has reached its timeout
  <font color="#924B72">#PB_Event_CloseWindow</font>     : the window close gadget has been pushed
  <font color="#924B72">#PB_Event_Repaint</font>         : the window content has been destroyed and must be repainted (useful for <a href="../2ddrawing/index.html">2D graphics operations</a>)
  <font color="#924B72">#PB_Event_SizeWindow</font>      : the window has been resized
  <font color="#924B72">#PB_Event_MoveWindow</font>      : the window has been moved
  <font color="#924B72">#PB_Event_MinimizeWindow</font>  : the window has been minimized
  <font color="#924B72">#PB_Event_MaximizeWindow</font>  : the window has been maximized
  <font color="#924B72">#PB_Event_RestoreWindow</font>   : the window has been restored to normal size (either from a minimum or maximum size)
  <font color="#924B72">#PB_Event_ActivateWindow</font>  : the window has been activated (got the focus)
  <font color="#924B72">#PB_Event_DeactivateWindow</font>: the window has been deactivated (lost the focus)
  <font color="#924B72">#PB_Event_WindowDrop</font>      : a <a href="../dragdrop/index.html">Drag &amp; Drop</a> operation was finished on a window
  <font color="#924B72">#PB_Event_GadgetDrop</font>      : a <a href="../dragdrop/index.html">Drag &amp; Drop</a> operation was finished on a <a href="../gadget/index.html">gadget</a> 
  <font color="#924B72">#PB_Event_RightClick</font>      : a right mouse button click has occurred on the window. This can be useful to display a popup menu
  <font color="#924B72">#PB_Event_LeftClick</font>       : a left mouse button click has occurred on the window
  <font color="#924B72">#PB_Event_LeftDoubleClick</font> : a left mouse button double-click has occurred on the window
  
</font></pre>

A basic example for event handling can be found in the <a href="waitwindowevent.html">WaitWindowEvent()</a> description. 

 

</blockquote><p><b>备注</b></p><blockquote>

After a <font color="#924B72">#PB_Event_WindowDrop</font> or <font color="#924B72">#PB_Event_GadgetDrop</font> Event, the event functions of the <a href="../dragdrop/index.html">Drag &amp; Drop library</a> can be used to examine and read the dropped data. <br><br><b>Important:</b> The window event loop should not be processed in a <a href="../thread/index.html">thread</a>, as there is some limitation on OS X and Linux. 调试器错误将被提高。<br><br>Correct way to handle an infinite WindowEvent() loop: 
<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#3A3966">Repeat</font></b>
    Event =<font color="#3A3966"> WindowEvent</font>()

    <b><font color="#3A3966">If</font></b> Event    <font color="#3A3966">; An event was in the queue so process it </font>
      ....
    <b><font color="#3A3966">Else</font></b>  
<font color="#3A3966">      Delay</font>(1)  <font color="#3A3966">; No event, let the others apps get some CPU time too !</font>
    <b><font color="#3A3966">EndIf</font></b>
  <b><font color="#3A3966">Until</font></b> Event = <font color="#924B72">#PB_Event_CloseWindow</font>
</font></pre>
<b>Important:</b> The 'Delay' shouldn't be put after each event, because when lot of events will come 
(like refresh, gadgets updates etc..) the app will wait between each event. So the delay need to be put 
when no events are received. Other (recommened) ways is to use <a href="waitwindowevent.html">WaitWindowEvent()</a> with a small timeout value, 
or setup a timer with <a href="addwindowtimer.html">AddWindowTimer()</a>.<br>
<b>Important:</b> If you use a <a href="../screen/flipbuffers.html">FlipBuffers()</a> somewhere in your code, so 
the 'Delay(1)' is not necessary. 

 

</blockquote><p><b>Example:</b> n? With Gadget</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">    <b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenWindow</font>(0, 0, 0, 600, 100, "Position of the mouse on the window: ", <font color="#924B72">#PB_Window_SystemMenu</font> | <font color="#924B72">#PB_Window_ScreenCentered</font>)
<font color="#3A3966">    TextGadget</font>(0, 10, 6, 200, 20, "")
    
    <b><font color="#3A3966">Repeat</font></b>
      Event =<font color="#3A3966"> WindowEvent</font>()
      
      <b><font color="#3A3966">If</font></b> Event &lt;&gt; 0 <font color="#3A3966">; All events are treated, so we can display the coordinates of the mouse</font>
<font color="#3A3966">        SetWindowTitle</font>(0, "Position of the mouse on the window: " +<font color="#3A3966"> Str</font>(<font color="#3A3966">WindowMouseX</font>(0)) + "," +<font color="#3A3966"> Str</font>(<font color="#3A3966">WindowMouseX</font>(0)))
      <b><font color="#3A3966">Else</font></b>
      
<font color="#3A3966">      Delay</font>(1) <font color="#3A3966">; Without a FlipBuffers(), Delay() frees the CPU for the multitasking</font>
      <b><font color="#3A3966">EndIf</font></b>
    <b><font color="#3A3966">Until</font></b> Event = <font color="#924B72">#PB_Event_CloseWindow</font>
  <b><font color="#3A3966">EndIf</font></b>
</font></pre>

</blockquote><p><b>Example:</b> n? With Gadget</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#3A3966">If</font></b> <font color="#3A3966">OpenWindow</font>(0, 0, 0, 300, 30, "Position of the mouse on the desktop", <font color="#924B72">#PB_Window_SystemMenu</font> | <font color="#924B72">#PB_Window_ScreenCentered</font>)
<font color="#3A3966">    TextGadget</font>(0, 10, 6, 200, 20, "")
    
    <b><font color="#3A3966">Repeat</font></b>
      Event =<font color="#3A3966"> WindowEvent</font>()
      
      <b><font color="#3A3966">If</font></b> Event = 0 <font color="#3A3966">; No more events in the queue, so we can display the coordinates of the mouse</font>
<font color="#3A3966">        SetGadgetText</font>(0, "Coordinates: "+<font color="#3A3966">Str</font>(<font color="#3A3966">DesktopMouseX</font>())+","+<font color="#3A3966">Str</font>(<font color="#3A3966">DesktopMouseY</font>()))
      <b><font color="#3A3966">EndIf</font></b>
      
<font color="#3A3966">      Delay</font>(20) <font color="#3A3966">;  Without a FlipBuffers(), Delay() frees the CPU for the multitasking</font>
      
    <b><font color="#3A3966">Until</font></b> Event = <font color="#924B72">#PB_Event_CloseWindow</font>
  <b><font color="#3A3966">EndIf</font></b>
</font></pre>

</blockquote><p><b>Example:</b> Without Gadgets (General case)</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">;Few variables</font>
  BallX = 400
  BallY = 200
  BallSpeedY.f = 5
  Gravitation.f = 2

  <font color="#3A3966">;Initialization </font>
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">InitSprite</font>()
<font color="#3A3966">    InitKeyboard</font>()
<font color="#3A3966">    InitMouse</font>()
  <b><font color="#3A3966">EndIf</font></b>

  <font color="#3A3966">;Window</font>
<font color="#3A3966">  OpenWindow</font>(0, 0, 0, 800, 600, "WindowEvent", <font color="#924B72">#PB_Window_SystemMenu</font>|<font color="#924B72">#PB_Window_ScreenCentered</font>)
<font color="#3A3966">  OpenWindowedScreen</font>(<font color="#3A3966">WindowID</font>(0), 0, 0, 800, 600)

  <font color="#3A3966">;Ground</font>
  Ground =<font color="#3A3966"> CreateSprite</font>(<font color="#924B72">#PB_Any</font>, 800, 30)
<font color="#3A3966">  StartDrawing</font>(<font color="#3A3966">SpriteOutput</font>(Ground))
<font color="#3A3966">  Box</font>(0,0,800,30,<font color="#3A3966">RGB</font>(128, 0, 0))
<font color="#3A3966">  StopDrawing</font>()

  <font color="#3A3966">;Ball</font>
  Ball =<font color="#3A3966"> CreateSprite</font>(<font color="#924B72">#PB_Any</font>, 16, 16)
<font color="#3A3966">  StartDrawing</font>(<font color="#3A3966">SpriteOutput</font>(Ball))
<font color="#3A3966">  Box</font>(0,0,16,16,<font color="#3A3966">RGB</font>(135, 206, 235))
<font color="#3A3966">  Circle</font>(8,8,8,<font color="#3A3966">RGB</font>(255, 255, 0))
<font color="#3A3966">  StopDrawing</font>()

  <font color="#3A3966">;Gauge</font>
  Image =<font color="#3A3966"> CreateImage</font>(<font color="#924B72">#PB_Any</font>, 8, 8, 24,<font color="#3A3966"> RGB</font>(255, 255, 255))
  *Buffer=<font color="#3A3966">EncodeImage</font>(Image ,<font color="#924B72">#PB_ImagePlugin_BMP</font>)
  Gauge =<font color="#3A3966"> CatchSprite</font>(<font color="#924B72">#PB_Any</font>, *Buffer)

  
  <font color="#3A3966">;Main Loop</font>
  <b><font color="#3A3966">Repeat</font></b>
  
    <b><font color="#3A3966">Repeat</font></b>
    <font color="#3A3966">;Window events</font>
    <font color="#3A3966">;====================================</font>
    <font color="#3A3966">;Try all possibilities but only one at a time</font>
    Event =<font color="#3A3966"> WindowEvent</font>()    <font color="#3A3966">; Animation</font>
    <font color="#3A3966">;Event = WaitWindowEvent()  ; Blocking animation</font>
    <font color="#3A3966">;Event = WaitWindowEvent(1) ; Animation but a 1ms unnecessary delay and furthermore it's a </font>
                                <font color="#3A3966">; bad way to program events because the queue is not empty</font>

    <b><font color="#3A3966">Select</font></b> Event
      <b><font color="#3A3966">Case</font></b> <font color="#924B72">#PB_Event_CloseWindow</font>
      <b><font color="#3A3966">End</font></b>
    <b><font color="#3A3966">EndSelect</font></b>
    <b><font color="#3A3966">Until</font></b> Event=0
    
<font color="#3A3966">    FlipBuffers</font>() <font color="#3A3966">; ==&gt; With WindowEvent(), FlipBuffers() frees the CPU for the multitasking so Delay(1) is not necessary </font>
<font color="#3A3966">    ClearScreen</font>(<font color="#3A3966">RGB</font>(135, 206, 235))
    
<font color="#3A3966">    ExamineKeyboard</font>() <font color="#3A3966">;Keyboard</font>
     
<font color="#3A3966">    DisplaySprite</font>(Gauge, 50, 570-BallY) <font color="#3A3966">;Display the gauge</font>
<font color="#3A3966">    ZoomSprite</font>(Gauge,  20, 570)
     
<font color="#3A3966">    DisplaySprite</font>(Ground, 0, 570) <font color="#3A3966">;Display the ground</font>
    
<font color="#3A3966">    DisplaySprite</font>(Ball, BallX, BallY) <font color="#3A3966">;Display the ball</font>
    
    <font color="#3A3966">;Ball Movement </font>
    BallSpeedY = BallSpeedY + Gravitation
    BallY = BallY + BallSpeedY
    
    <font color="#3A3966">;Management of the collision of the ball with the ground</font>
    <b><font color="#3A3966">If</font></b> <font color="#3A3966">SpriteCollision</font>(Ball, BallX, BallY+16, Ground, 0, 570)
    BallY= 554
    BallSpeedY = -BallSpeedY
    <b><font color="#3A3966">EndIf</font></b>
    
  <b><font color="#3A3966">Until</font></b> <font color="#3A3966">KeyboardPushed</font>(<font color="#924B72">#PB_Key_Escape</font>)
</font></pre>

</blockquote><p><b>参阅</b></p><blockquote>

<a href="waitwindowevent.html">WaitWindowEvent()</a>, <a href="eventwindow.html">EventWindow()</a>, 
<a href="eventgadget.html">EventGadget()</a>, <a href="eventmenu.html">EventMenu()</a>, 
<a href="eventtimer.html">EventTimer()</a>, <a href="eventdata.html">EventData()</a>, 
<a href="eventtype.html">EventType()</a>, <a href="postevent.html">PostEvent()</a>, 
<a href="bindevent.html">BindEvent()</a>, <a href="unbindevent.html">UnbindEvent()</a> 

</Blockquote><p><b>已支持操作系统 </b><Blockquote>所有</Blockquote></p><center>&lt;- <a href=windowbounds.html>WindowBounds()</a> - <a href="index.html">Window Index</a> - <a href="windowheight.html">WindowHeight()</a> -&gt;<br><br>

</body></html>